// 一些装备用的功能
const mongoose = require('mongoose');
const ShopGood = require('../../../models/Shop/Shop_good');

async function check_shop_good_full(sid) {
    // 拿到商店的id和商品的id，然后判断还有没有库存
    let flag = true;
    // 用eid,sid去获取该商品
    let ready_use_shopgood = await ShopGood.findOne({
        _id: sid
    })
    if (ready_use_shopgood.count > 0) {
        return flag;
    } else {
        flag = false;
        return flag;
    }
}
async function shop_good_reduce(sid) {
    // 减库存
    let flag1 = true;
    let flag2 = true;
    // 用eid,sid去获取该商品
    let ready_use_shopgood = await ShopGood.findOne({
        _id: sid
    })
    // 获得当前商品数量
    let goods_count = ready_use_shopgood.count;
    if (flag1) {
        const ShopGood_Fields = {};
        // 数量减1
        ShopGood_Fields.count = goods_count - 1;
        await ShopGood.findOneAndUpdate({
            _id: sid
        }, {
            $set: ShopGood_Fields
        }, {
            new: true
        }).then(shopgood => console.log("减少",shopgood._id,"的库存为",shopgood.count));
        return flag2;
    } else {
        flag2 = false;
        return flag2;
    }
}
async function shop_good_add(sid) {
    // 加库存

}
async function shop_good_refill(sid) {
    // 定时加库存方法

}

module.exports = {
    check_shop_good_full: check_shop_good_full,
    shop_good_reduce: shop_good_reduce
};